package com.library.controller.user;

import com.library.result.Result;
import com.library.service.SocializeService;
import com.library.vo.UserProfileVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user")
@Slf4j
@Api(tags = "社交模块")
public class SocializeController {

    @Autowired
    private SocializeService socializeService;

    @GetMapping("/{userId}/profile")
    @ApiOperation("获取用户个人资料")
    public Result<UserProfileVO> getUserProfile(@PathVariable Long userId) {
        log.info("获取用户个人资料，userId:{}", userId);
        UserProfileVO userProfileVO = socializeService.getUserProfile(userId);
        return Result.success(userProfileVO);
    }

    @PostMapping("/{userId}/follow")
    @ApiOperation("关注用户")
    public Result<String> follow(@PathVariable Long userId) {
        log.info("关注用户，userId:{}", userId);
        socializeService.follow(userId);
        return Result.success();
    }

    @GetMapping("/{userId}/followers")
    @ApiOperation("获取用户的关注者列表")
    public Result<List<UserProfileVO>> getFollowers(@PathVariable Long userId) {
        log.info("获取用户的关注者列表，userId:{}", userId);
        List<UserProfileVO> followers = socializeService.getFollowers(userId);
        return Result.success(followers);
    }

    @GetMapping("/{userId}/following")
    @ApiOperation("获取用户的关注列表")
    public Result<List<UserProfileVO>> getFollowing(@PathVariable Long userId) {
        log.info("获取用户的关注列表，userId:{}", userId);
        List<UserProfileVO> following = socializeService.getFollowing(userId);
        return Result.success(following);
    }


}
